#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXN = 1e5 + 10;

int n, q;
int f[MAXN], son[MAXN];

void init() {
    for (int i = 0; i < MAXN; i++) {
        f[i] = i;
        son[i] = i;
    }
}

int find(int x) {
    if (x == f[x]) {
        return x;
    }
    return find(f[x]);
}

void merge (int x, int y) {
    f[y] = x;
    son[x] = y;
}

void del(int x, int y) {
    f[y] = y;
    son[x] = x;
}

void output(int x) {
    int t = find(x);

    vector<int> v;
    while(son[t] != t) {
        v.push_back(t);
        t = son[t];
    }
    v.push_back(t);
    cout << v.size() << ' ';
    for (auto it : v) {
        cout << it << ' ';
    }
    cout << endl;
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    init();
    int op, x, y;
    cin >> n >> q;

    while(q--) {
        cin >> op;
        if (op == 1) {
            cin >> x >> y;
            merge(x, y);
        } else if (op == 2) {
            cin >> x >>y;
            del(x, y);
        } else if (op == 3) {
            cin >> x;
            output(x);
        }
    }
    return 0;
}